<template>
  <div class="page-home">
    <div class="home-entry">
      <div class="container">
        <!-- 左侧分类 -->
        <home-category />
        <!-- banner轮播图 -->
        <home-banner />
        <!-- 新鲜好物 -->
        <home-panel title="新鲜好物" subTitle="新鲜出炉 品质靠谱">
          <template #right>
            <span>查看更多</span>
          </template>
          <template #main>
            <ul class="goods-list">
              <li v-for="item in newGoodsList" :key="item.id">
                <RouterLink :to="`/good/${item.id}`">
                  <img v-img-lazy="item.picture" alt="" />
                  <p class="name">{{ item.name }}</p>
                  <p class="price">{{ item.price }}</p>
                </RouterLink>
              </li>
            </ul>
          </template>
        </home-panel>
        <!-- 人气推荐 -->
        <home-panel title="人气推荐" subTitle="人气推荐 不容错过">
          <template #main>
            <ul class="goods-list">
              <li v-for="item in findHotList" :key="item.id">
                <RouterLink to="/">
                  <img v-img-lazy="item.picture" alt="" />
                  <p>{{ item.title }}</p>
                  <p>{{ item.alt }}</p>
                </RouterLink>
              </li>
            </ul>
          </template>
        </home-panel>
        <!-- 热门品牌 -->
        <home-panel title="热门品牌" subTitle="国际经典 品牌保障">
          <template #main>
            <ul class="brand-list">
              <li v-for="item in brandList" :key="item.id">
                <img v-img-lazy="item.picture" alt="" />
              </li>
            </ul>
          </template>
        </home-panel>
      </div>
    </div>
  </div>
</template>

<script>
import { ref } from 'vue'
// 引入分类菜单页和轮播图
import HomeCategory from './components/home-category.vue'
import HomeBanner from './components/home-banner.vue'
// 引入复用组件部分
import HomePanel from './components/home-pannel.vue'
// 引入接口Api请求
import { popularHotApi, getBrandApi, getNewGoodsApi } from '@/api/home'
export default {
  name: 'home-vue',
  components: {
    HomeCategory,
    HomeBanner,
    HomePanel
  },
  setup () {
    // 获取人气推荐
    const findHotList = ref([])
    async function getFindHot () {
      const res = await popularHotApi()
      findHotList.value = res.result
    }
    getFindHot()
    // 获取热门品牌
    const brandList = ref([])
    async function getbrandList () {
      const res = await getBrandApi(7)
      brandList.value = res.result
    }
    getbrandList()

    // 获取新鲜好物
    const newGoodsList = ref([])
    const getNewGoodsList = async _ => {
      const res = await getNewGoodsApi()
      newGoodsList.value = res.result
    }
    getNewGoodsList()

    return {
      findHotList,
      brandList,
      newGoodsList
    }
  }
}
</script>

<style scoped lang='less'>
.goods-list {
  display: flex;
  justify-content: space-between;
  height: 426px;
  li {
    width: 306px;
    height: 406px;
    background-color: rgb(240, 249, 244);
    img {
      width: 306px;
      height: 306px;
    }
    p {
      font-size: 22px;
      padding-top: 12px;
      text-align: center;
      // .name
      text-overflow: ellipsis;
      overflow: hidden;
      white-space: nowrap;
    }
    .desc {
      color: #999;
      font-size: 18px;
    }
    .price {
      color: @priceColor;
    }
  }
}

.brand-list {
  display: flex;
  li {
    flex: 1;
    padding: 10px;
  }
}
</style>
